﻿<%@ Page Language="C#" MasterPageFile="~/Manager.master" AutoEventWireup="true" CodeFile="SignOrderPD.aspx.cs"
    Inherits="Manager_OrderDetail_SignOrderPD" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script language="javascript" src="../../Pub/Js/jquery.js" type="text/javascript"></script>

    <div>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="center" nowrap>
                    <table cellpadding="2" cellspacing="0" border="0">
                        <tr>
                            <td>
                                <asp:Panel ID="pnlControl" runat="server" widht="100%" Width="100%">
                                    <asp:Button ID="btnOk" runat="server" CssClass="cssButton" OnClick="btnOk_Click"
                                        Text="Xác nhận" />
                                    <asp:Button ID="btnSending" runat="server" CssClass="cssButton" OnClick="btnSending_Click"
                                        Text="Đang giao hàng" Width="120px" OnClientClick="return CheckQuantityValidOK()" />
                                    <asp:Button ID="btnSend" runat="server" CssClass="cssButton" OnClick="btnSend_Click"
                                        Text="Đã giao hàng" OnClientClick="return CheckMoneyValidOK()" Width="120px" />
                                    <asp:Button ID="btnCancel" runat="server" CssClass="cssButton" OnClick="btnCancel_Click"
                                        Text="Hủy bỏ" />
                                </asp:Panel>
                            </td>
                            <td>
                                <asp:Button ID="btnBack" runat="server" CssClass="cssButton" OnClick="btnBack_Click"
                                    Text="Quay về" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="printBody">
                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                            <tr>
                                <td>
                                    <table border="0" bordercolor="#407db3" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
                                        width="100%">
                                        <tr>
                                            <td colspan="4" align="center" valign="top">
                                                <asp:Label ID="lblTitle" runat="server" Text="" Font-Bold="True" Font-Size="14px"
                                                    Font-Names="Tahoma"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td align="right" colspan="4" valign="bottom">
                                                <table border="0" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td align="left">
                                                            Mã đơn hàng</td>
                                                        <td align="left" valign="middle" style="white-space: nowrap">
                                                            :&nbsp;<asp:Label ID="lblMaDH" runat="server" Text="" Font-Bold="true"></asp:Label></td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4">
                                                <table id="AutoNumber1" style="border-right: 1px solid; padding-right: 0px; border-top: 1px solid;
                                                    padding-left: 0px; padding-bottom: 0px; border-left: 1px solid; padding-top: 1px;
                                                    border-bottom: 1px solid; border-collapse: collapse" bordercolor="#111111" cellspacing="0"
                                                    cellpadding="2" width="100%" runat="server">
                                                    <tr>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; width: 95px; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;" align="left">
                                                            Tên khách hàng</td>
                                                        <td align="left" colspan="3" nowrap="nowrap" style="padding-right: 4px; padding-left: 4px;
                                                            padding-bottom: 1px; padding-top: 1px; border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;">
                                                            :&nbsp;<asp:Label ID="lblTenKH" runat="server" Text=""></asp:Label></td>
                                                    </tr>
                                                    <tr>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; width: 95px; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;" align="left">
                                                            Địa chỉ</td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;"
                                                            align="left">
                                                            :&nbsp;<asp:Label ID="lblDiaChi" runat="server" Text=""></asp:Label></td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; width: 114px; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;" align="left">
                                                            Tỉnh, Thành Phố</td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;"
                                                            align="left">
                                                            :&nbsp;<asp:Label ID="lblNoichon" runat="server" Text=""></asp:Label></td>
                                                    </tr>
                                                    <tr id="trTaxNo" runat="server">
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; width: 95px; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;" align="left">
                                                            Mã số thuế</td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;"
                                                            colspan="3" align="left">
                                                            :&nbsp;<asp:Label ID="lblTaxNo" runat="server"></asp:Label></td>
                                                    </tr>
                                                    <tr>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; width: 95px; font-family: Tahoma,Arial,Helvetica,sans-serif;
                                                            font-size: 12px;" align="left">
                                                            Điện thoại</td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;"
                                                            align="left">
                                                            :&nbsp;<asp:Label ID="lblSDT" runat="server" Text=""></asp:Label></td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;
                                                            width: 114px;" align="left">
                                                            Email</td>
                                                        <td nowrap style="padding-right: 4px; padding-left: 4px; padding-bottom: 2px; padding-top: 2px;
                                                            border-bottom: 1px dotted; font-family: Tahoma,Arial,Helvetica,sans-serif; font-size: 12px;"
                                                            align="left">
                                                            :&nbsp;<asp:Label ID="lblEmail" runat="server" Text=""></asp:Label></td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="left" colspan="2" nowrap="nowrap">
                                                &nbsp;</td>
                                            <td align="right" colspan="2">
                                                <asp:Label ID="lblUSD" runat="server"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4">
                                                <asp:GridView ID="grvMaster" runat="server" GridLines="Both" BorderStyle="Solid"
                                                    AutoGenerateColumns="False" Width="100%" BorderWidth="1px" BorderColor="#407db3"
                                                    OnRowDataBound="grvMaster_RowDataBound" CellPadding="2" CellSpacing="0">
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="STT">
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>
                                                                <%#Container.DataItemIndex + 1%>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:BoundField DataField="PDID" HeaderText="Mã Sản phẩm">
                                                            <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Left" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3"
                                                                Width="2%" Wrap="false" />
                                                        </asp:BoundField>
                                                        <asp:BoundField DataField="PDName" HeaderText="Tên sản phẩm">
                                                            <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Left" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3"
                                                                Width="35%" Wrap="false" />
                                                        </asp:BoundField>
                                                        <asp:BoundField DataField="Quantity" HeaderText="Số lượng">
                                                            <ItemStyle HorizontalAlign="Center" CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3"
                                                                Width="4%" Wrap="false" />
                                                        </asp:BoundField>
                                                        <asp:TemplateField HeaderText="Kho">
                                                            <ItemStyle HorizontalAlign="Center" Width="1%" />
                                                            <ItemTemplate>
                                                                <asp:DropDownList ID="ddlStore" runat="server" DataSource='<%# GetStoreList() %>'
                                                                    DataTextField="StName" DataValueField="StID" onchange="fnSetQuantity(this)">
                                                                </asp:DropDownList>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" Wrap="false" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="S/L Kho">
                                                            <ItemStyle HorizontalAlign="Center" Width="1%" />
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblQuantityStore" runat="server" Text=''></asp:Label>
                                                                <asp:Label ID="lblKindNo" runat="server" Text='<%# Eval("KindNo") %>' Style="display: none;
                                                                    visibility: hidden"></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" Wrap="false" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Đơn giá">
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblDonGia" runat="server" Text='<%# Eval("Price") %>'></asp:Label>
                                                                <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>'></asp:Label>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Right" BorderStyle="Solid"
                                                                BorderColor="#407db3" Wrap="false" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText='Giá mới'>
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>
                                                                <asp:TextBox ID="txtSaleOfPrice" runat="server" Width="105px" CssClass="txt_Product"
                                                                    Height="18px" Text="0" Style="text-align: right" onkeyup="fnCalSaleOf(this)"></asp:TextBox>
                                                                <asp:TextBox ID="TextBox1" ReadOnly="true" BorderStyle="None" BackColor="Gainsboro"
                                                                    Font-Size="11px" CssClass="txt_Product" runat="server" Width="28px" Text='<%# Eval("Rate") %>'
                                                                    Style="text-align: right"></asp:TextBox>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" Wrap="false" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Thanh toán (VNĐ)">
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>
                                                                <asp:TextBox ID="lblTotal" runat="server" Text='<%# Eval("Total") %>' Width="100%"
                                                                    onfocus="fnReadOnlyText(this)" Style="text-align: right; border: 0; width: 110px"></asp:TextBox>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" Wrap="false" />
                                                            <HeaderStyle CssClass="cssBorderGrv" Wrap="false" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Ghi chú">
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>
                                                                <asp:TextBox ID="txtNoteDetail" runat="server" Width="150px" Font-Size="11px" Text='<%# Eval("NoteDetail") %>'></asp:TextBox>
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" Wrap="false" />
                                                            <HeaderStyle CssClass="cssBorderGrv" Wrap="false" BorderWidth="1px" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                        </asp:TemplateField>
                                                        <%-- <asp:TemplateField HeaderText="Tổng kho">
                                                            <ItemStyle HorizontalAlign="Center" Width="2%" />
                                                            <ItemTemplate>                                                             
                                                            </ItemTemplate>
                                                            <ItemStyle CssClass="cssBorderGrv" BorderWidth="1px" HorizontalAlign="Center" BorderStyle="Solid"
                                                                BorderColor="#407db3" />
                                                            <HeaderStyle CssClass="cssBorderGrv" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" />
                                                        </asp:TemplateField>--%>
                                                    </Columns>
                                                    <HeaderStyle Height="30px" Wrap="false" BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3"
                                                        BackColor="#f7f8f9" ForeColor="#000000" Font-Bold="true" />
                                                    <RowStyle BorderWidth="1px" BorderStyle="Solid" BorderColor="#407db3" Font-Names="Tahoma"
                                                        Font-Size="12px" />
                                                    <AlternatingRowStyle BackColor="snow" Font-Names="Tahoma" Font-Size="12px" />
                                                </asp:GridView>
                                                <br />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="4">
                                                <table border="0" bordercolor="#407db3" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
                                                    <tr>
                                                        <td align="center" colspan="6" style="white-space: nowrap; background-color: Honeydew"
                                                            valign="bottom">
                                                            <asp:CheckBox ID="chkPayment" runat="server" Text="Đã thanh toán đầy đủ" Style="cursor: pointer"
                                                                Visible="false" />
                                                            <table cellpadding="3" cellspacing="0" id="tblPaymoney" runat="server">
                                                                <tr>
                                                                    <td>
                                                                        Số tiền trả:
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="txtPaidMoney" runat="server" onkeyup="fnDisplayTextMoney(this)"
                                                                            Style="text-align: right" Width="120px" CssClass="txt_Product" Text="0"></asp:TextBox>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="TextBox2" ReadOnly="true" BorderStyle="None" BackColor="TRansparent"
                                                                            Font-Size="11px" CssClass="txt_Product" runat="server" Width="28px" Text='VNĐ'
                                                                            Style="text-align: right"></asp:TextBox>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="right" valign="bottom" style="white-space: nowrap; padding-right: 10px;">
                                                            <asp:Label ID="Label14" runat="server" Text="Tổng số lượng: " Font-Bold="True"></asp:Label></td>
                                                        <td align="right" colspan="2" style="width: 120px; border-bottom: black thin dotted;
                                                            white-space: nowrap;" valign="bottom">
                                                            <asp:Label ID="lblQuantity" runat="server" Font-Names="tahoma" Font-Size="12px"></asp:Label></td>
                                                        <td align="right" style="width: 2%; white-space: nowrap">
                                                        </td>
                                                        <td align="right" style="white-space: nowrap; padding-right: 10px;" valign="bottom"
                                                            runat="server" id="td1">
                                                            <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Số tiền đã trả:"></asp:Label></td>
                                                        <td align="right" style="border-bottom: black thin dotted; white-space: nowrap;"
                                                            valign="bottom" runat="server" id="td2">
                                                            <asp:TextBox ID="txtRepaid" runat="server" Style="text-align: right; border: 0" onfocus="fnReadOnlyText(this)"
                                                                CssClass="txt_Product" Height="18px" Width="120px"></asp:TextBox>&nbsp;
                                                            <asp:TextBox ID="txt" runat="server" BorderStyle="None" CssClass="txt_Product" Font-Size="11px"
                                                                ReadOnly="true" Style="text-align: right" Text="VNĐ" Width="28px"></asp:TextBox></td>
                                                    </tr>
                                                    <tr>
                                                        <td align="right" style="white-space: nowrap; padding-right: 10px;" valign="bottom">
                                                            <asp:Label ID="Label15" runat="server" Text="Tổng số tiền thanh toán: " Font-Bold="True"></asp:Label></td>
                                                        <td align="right" colspan="2" style="border-bottom: black thin dotted; white-space: nowrap;"
                                                            valign="bottom">
                                                            <asp:TextBox ID="lblTongsotien" runat="server" CssClass="txt_Product" Height="18px"
                                                                onfocus="fnReadOnlyText(this)" Style="border-right: 0px; border-top: 0px; border-left: 0px;
                                                                border-bottom: 0px; text-align: right" Width="120px"></asp:TextBox>
                                                            <asp:TextBox ID="TextBox4" runat="server" BorderStyle="None" CssClass="txt_Product"
                                                                Font-Size="11px" ReadOnly="true" Style="text-align: right" Text="VNĐ" Width="28px"></asp:TextBox></td>
                                                        <td align="right" style="width: 2%; white-space: nowrap">
                                                        </td>
                                                        <td align="right" style="white-space: nowrap; padding-right: 10px;" valign="bottom"
                                                            runat="server" id="td3">
                                                            <asp:Label ID="Label3" runat="server" Font-Bold="True" Text="Số tiền còn thiếu lại:"></asp:Label></td>
                                                        <td align="right" style="border-bottom: black thin dotted; white-space: nowrap;"
                                                            valign="bottom" runat="server" id="td4">
                                                            <asp:TextBox ID="txtRemainPrice" runat="server" CssClass="txt_Product" Height="18px"
                                                                Style="text-align: right; border: 0" onfocus="fnReadOnlyText(this)" Width="120px"></asp:TextBox>
                                                            <asp:TextBox ID="TextBox1" ReadOnly="true" BorderStyle="None" Font-Size="11px" CssClass="txt_Product"
                                                                runat="server" Width="28px" Text='VNĐ' Style="text-align: right"></asp:TextBox>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" colspan="4">
                                                &nbsp;</td>
                                        </tr>
                                    </table>
                                    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%"  >
                                        <tr id="tdNoteCus" runat="server">
                                            <td align="center" style="padding-left: 10px; width: 12%; white-space: nowrap">
                                                <asp:Label ID="Label2" runat="server" Style="padding-left: 5%" Text="Ghi chú khách hàng: " Font-Bold="true"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblNoteCus" runat="server"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td align="center" style="padding-left: 10px; width: 12%; white-space: nowrap">
                                                &nbsp;
                                            </td>
                                            <td>
                                            </td>
                                        </tr>
                                        <tr  id="tdNote" runat="server">
                                            <td align="center" style="padding-left: 10px; width: 12%; white-space: nowrap;">
                                                <asp:Label ID="lblNoteOrder" runat="server" Text="Ghi chú: " Style="padding-left: 5%" Font-Bold="true"></asp:Label></td>
                                            <td>
                                                <asp:TextBox ID="txtNote" runat="server" Height="67px" TextMode="MultiLine" Width="95%"
                                                    CssClass="txt_Product" BorderStyle="Groove"></asp:TextBox>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" runat="server" id="hidMethod" />
    <input type="hidden" runat="server" id="hidRate" />
    <input type="hidden" runat="server" id="hidRemainPrice" />
    <input type="hidden" runat="server" id="hidRepaid" />
    <input type="text" readonly="readonly" id="txtReadOnly" runat="server" style="text-align: right;
        border: 0" />

    <script language="javascript" type="text/javascript">
    
   
   /* $(document).ready(function() {
        $("#<%=chkPayment.ClientID %>").click(function()
        {                 
            $objChkPay=$(this);
            var colPay=7;
            if('<%= Request.QueryString["State"]%>'=="Y")             
                colPay+=1;
            $("#<%= grvMaster.ClientID %>").find('tr').each(function(index){
                if(index!="0")
                {   
                    var sRepaid="0" ; 
                    $objTR=$(this);                  
                    if($objChkPay.attr('checked')==true)
                    {   
                        sRepaid=$objTR.find('td:eq('+colPay+1+')').find('input:eq(0)').attr('value');                             
                    }                            
                    $objTR.find('td:eq('+colPay+')').find('input:eq(0)').attr({'value':sRepaid});
                }
            });                   
        });
     });
    */
    
    function fnDisplayTextMoney(obj)
    {
        obj.value=FormatMoney(obj.value.ReplaceAll(",",""))   ; 
    }
    function fnReadOnlyText(obj)
    {
        document.getElementById("<%= txtReadOnly.ClientID %>").focus();
    }
    var ddlStore;
    function fnSetQuantity(obj)
    {
      ddlStore=obj;
      Manager_OrderDetail_SignOrderPD.GetQuantityStore(obj.parentNode.parentNode.cells[1].innerHTML,obj.value,CallBackQuantityStore) ;
      
    }
    function CallBackQuantityStore(res)
    {
        if(res!=null)
        {
           var sValue=res.value;
           if(sValue!="" && sValue!=null) 
          {
            ddlStore.parentNode.parentNode.cells[5].getElementsByTagName('span')[0].innerHTML=sValue;
            
            var q_Order=ddlStore.parentNode.parentNode.cells[3].innerHTML;
            if(parseInt(sValue)<parseInt(q_Order))
            {
                ddlStore.parentNode.parentNode.cells[5].style.backgroundColor="Orange";
            }
            else
            {
                ddlStore.parentNode.parentNode.cells[5].style.backgroundColor=ddlStore.parentNode.parentNode.style.backgroundColor;
            }
          } 
        }
    }
    function CheckQuantityValid()
    {
        var tbl=document.getElementById("<%= grvMaster.ClientID%>");
        for(var i=1;i<tbl.rows.length;i++)
        {
           var PDID=tbl.rows[i].cells[1].innerHTML;
           var PDNm=tbl.rows[i].cells[2].innerHTML;
           var q_Order=tbl.rows[i].cells[3].innerHTML;
           var q_Store=tbl.rows[i].cells[5].getElementsByTagName('span')[0].innerHTML;
           var KindNo= tbl.rows[i].cells[5].getElementsByTagName('span')[1].innerHTML
           if(KindNo=="P")
           {
                 if(parseInt(q_Store)<parseInt(q_Order))
                {
                    alert("Sản phẩm "+ PDNm+ " trong kho này không đủ số lượng") ;
                    return false;
                }  
           }  
        }
        return true;
    }
       function CheckQuantityValidOK()
        {
            var index=4;
            var State='<%= Request["State"] %>';
            if(State!="N")
                index=5;
            var tbl=document.getElementById("<%= grvMaster.ClientID%>");
            for(var i=1;i<tbl.rows.length;i++)
            {
               var PDID=tbl.rows[i].cells[1].innerHTML;
               var PDNm=tbl.rows[i].cells[2].innerHTML; 
               var q_Order=tbl.rows[i].cells[3].innerHTML;
               var q_Store=tbl.rows[i].cells[index].getElementsByTagName('span')[0].innerHTML;
               var KindNo= tbl.rows[i].cells[index].getElementsByTagName('span')[1].innerHTML
               if(KindNo=="P")
               {
                     if(parseInt(q_Store)<parseInt(q_Order))
                    {
                        alert("Sản phẩm "+ PDNm+ " trong kho này không đủ số lượng") ;
                        return false;
                    }  
               }  
            }
            return true;
        }
        function CheckMoneyValidOK()
        {      
            var flagQ=CheckQuantityValidOK();
            if(flagQ==false) return false;
            if($("#<%=txtRemainPrice.ClientID %>").attr('value')!="0")
           {
                alert('Bạn chưa thanh toán đủ số tiền còn thiếu') ;
                 return false;  
           }  
            
            return true;
        }   
    
    //=======================================================
    
    
        function fnCalSaleOf(obj)
        {       
        
               obj.value=FormatMoney(obj.value.ReplaceAll(",",""))   ;         
               var Quantity=obj.parentNode.parentNode.cells[3].innerHTML;
               var Rate=obj.parentNode.parentNode.cells[6].children[1].innerHTML;             
               var DiscountPrice=obj.value.ReplaceAll(",","");

              //neu = 0 lay lai gia goc 
               if(obj.value=="" || obj.value=="0")
               {   
                   DiscountPrice=obj.parentNode.parentNode.cells[6].children[0].innerHTML.ReplaceAll(",","");               
               }          
               var objTotalPrice=obj.parentNode.parentNode.cells[8].children[0];
               var TotalPrice= DiscountPrice*Quantity;           
               if (Rate=="USD")
               { 
                   var USD=document.getElementById("<%= hidRate.ClientID %>").value ;
                   TotalPrice*= USD;                
                }
          
                objTotalPrice.value=FormatMoney(TotalPrice);    
               //Tinh lai tong so luong 
               fnCalReTotal();      
               
               //Uncheck Payment
                 $("#<%=txtPaidMoney.ClientID %>").val("0");
               $("#<%=chkPayment.ClientID %>").removeAttr('checked')  ;
               $("#<%=txtRepaid.ClientID %>").attr({'value':'0'});
              fnCalRepaid($("#<%=txtRepaid.ClientID %>"));
            
        }        
        function fnCalReTotal()
        {
            $(document).ready(function() 
            {                     
                /*var colPay=7;
                if('<%= Request.QueryString["State"]%>'=="Y")             
                    colPay+=1;*/
                var sTotal=0 ; 
                $("#<%= grvMaster.ClientID %>").find('tr').each(function(index){
                    if(index!="0")
                    {                          
                        $objTR=$(this);                   
                        sTotal+=parseInt($objTR.find('td:eq(8)').find('input:eq(0)').attr('value').ReplaceAll(",","")); 
                      
                    }
                });
                 sTotal=FormatMoney(sTotal);
                $("#<%=txtRemainPrice.ClientID %>").attr({'value':sTotal});
                $("#<%=txtRepaid.ClientID %>").attr({'value':'0'}); 
                $("#<%=lblTongsotien.ClientID %>").attr({'value':sTotal})  ;          
            });
        }
        
        //Tinh toan tra truoc
        $(document).ready(function() 
        {
            $("#<%=txtPaidMoney.ClientID %>").keyup(function()
            {
                  fnCalRepaid($(this));
            });
        });
        
      $(document).ready(function() {
        $("#<%=chkPayment.ClientID %>").click(function()
        {           
                  fnCheckedPayment($(this));
        });
     });
     
        function fnCheckedPayment(obj)
        {               
               if(obj.attr('checked')==true)       
              {
                  $("#<%=txtRemainPrice.ClientID %>").attr({'value':'0'});
                  $("#<%=txtRepaid.ClientID %>").attr({'value':$("#<%=lblTongsotien.ClientID %>").attr('value')})  ; 
                  $("#<%=tblPaymoney.ClientID%>").hide();
              }
              else
              {
                   $("#<%=tblPaymoney.ClientID%>").show();
                   $("#<%=txtPaidMoney.ClientID %>").val("0");
                   var sRemainPrice=0;
                   if('<%=Request["State"] %>'=="S" || '<%=Request["State"] %>'=="Y")
                   {
                        sRemainPrice=$("#<%=hidRemainPrice.ClientID %>").attr('value');
                   }
                   var sRepaid=$("#<%=lblTongsotien.ClientID %>").attr('value').ReplaceAll(",","")-sRemainPrice;
                  $("#<%=txtRepaid.ClientID %>").attr({'value':FormatMoney(sRepaid)})
                  $("#<%=txtRemainPrice.ClientID %>").attr({'value':FormatMoney(sRemainPrice)})
              } 
        }
        function fnCalRepaid(obj)
        {
        
            if(obj.attr('value')!="")
            { 
                  $Remainpaid=parseInt(obj.attr('value').ReplaceAll(",",""))+parseInt($("#<%=hidRepaid.ClientID %>").attr('value').ReplaceAll(",",""));
            
                  
                
                   //Tong tien-(so tien tra truoc+so tien tra truoc dang nhap)
                  $RemainPrice=$("#<%=lblTongsotien.ClientID %>").attr('value').ReplaceAll(",","")-$Remainpaid;
                   
                  if($RemainPrice<0)
                  {
                    alert('Bạn đã nhập vượt quá số tiền cần thanh toán');
                    obj.focus();
                    obj.attr({'value':'0'});
                    fnCalRepaid(obj);
                    return;
                  }
                  else if($RemainPrice==0)
                     $("#<%=chkPayment.ClientID %>").attr({'checked':'checked'})  ;
                  else
                     $("#<%=chkPayment.ClientID %>").removeAttr('checked')  ;
                     
                  $("#<%=txtRemainPrice.ClientID %>").attr({'value':FormatMoney($RemainPrice)}); 
                  $("#<%=txtRepaid.ClientID %>").attr({'value':FormatMoney($Remainpaid)});
                                     
            }
        }
        
        
    
   
   
   

    </script>

</asp:Content>
